package com.zlq.cn.entity;

import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;

/**
 * <p>
 *
 * </p>
 *
 * @author zhoucl
 * @since 2022-03-05
 */
@Data
@Accessors(chain = true)
@TableName("fanyi_user")
public class FanyiUser {

    @ApiModelProperty("翻译用户imei")
    @TableId
    private String fanyiUserImei;

    @ApiModelProperty("苹果token")
    private String iosToken;

    @ApiModelProperty("vip等级")
    private Integer vipLevel;

    @ApiModelProperty("vip开始时间")
    private LocalDateTime vipStartTime;

    @ApiModelProperty("vip结束时间")
    private LocalDateTime vipEndTime;

    @ApiModelProperty("创建时间")
    private LocalDateTime createTime;

    @ApiModelProperty("上次登录时间")
    private LocalDateTime lastLoginTime;

    @ApiModelProperty("姓名")
    private String name;

    @ApiModelProperty("手机号码")
    private String phone;

    @ApiModelProperty("头像")
    private String avatar;

    @ApiModelProperty("token")
    private String token;

    @ApiModelProperty("免费次数")
    private Integer freeNumber;

    @ApiModelProperty("是否禁用")
    private Integer isDisable;

    @ApiModelProperty("项目")
    private String project;

    @ApiModelProperty("使用天数")
    @TableField(exist = false)
    private long useDay;

    @ApiModelProperty("vip剩余天数")
    @TableField(exist = false)
    private long surplusDay;

    @ApiModelProperty("到期提示")
    @TableField(exist = false)
    private String membershipExpirationDate;

    @ApiModelProperty("开关")
    @TableField(exist = false)
    private String open;

    @ApiModelProperty("开关")
    @TableField(exist = false)
    private String yaoqiuvip;

    @JsonIgnore
    @JSONField(deserialize = false, serialize = false)
    public boolean isVip() {
        LocalDateTime vipEndTime = getVipEndTime();
        long surplusDay = 0;
        if (vipEndTime != null && vipEndTime.isAfter(LocalDateTime.now())) {
            surplusDay = Math.abs(vipEndTime.toLocalDate().until(LocalDate.now(), ChronoUnit.DAYS));
        }
        return surplusDay > 0;
    }
}
